<!--  商机响应流程详情-->
<template>
  <div>
    <div v-if="requestError" class="text-c errorPlace">
      <img width="100px" height="100px" :src="require('@/assets/images/pic_neterror.png')" alt="获取数据失败" />
      <div class="color-b font14" style="margin: 10px 0 0 0">
        获取数据失败!
      </div>
      <van-button plain round size="small" color="#7232dd" type="primary" @click="getdetail">点击重试</van-button>
    </div>
    <van-form v-else @submit="submitFromData">
      <div class="font15 mt10 pl10">
        <span class="titletext">{{ detailData.title }}</span>
        <div class="graytext mt10 font13">
          <span>工单编号：</span>
          <span class="titletext">{{ fromdata.pmInsId }}</span>
        </div>
      </div>

      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">商机需求响应-基础信息</span> 
      </div>
      <van-field readonly required name="applicant" :value="fromdata.applicant" label="申请人：" label-width="4em" />
      <van-field readonly required name="applyNeedTime" :value="fromdata.applyNeedTime" label="需求申请时间：" label-width="7em" />
      <van-field readonly required name="city" :value="fromdata.city" label="地市：" label-width="3em" />
      <van-field readonly required name="county" :value="fromdata.county" label="县区：" label-width="3em" />
      <van-field readonly required name="businessId" :value="fromdata.businessId" label="商机编号：" label-width="5em" />
      <van-field readonly required name="businessName" :value="fromdata.businessName" label="商机名称：" label-width="5em" />
      <van-field readonly required name="customerName" :value="fromdata.customerName" label="集团客户名称：" label-width="7em" />
      <van-field readonly required name="customerCode" :value="fromdata.customerCode" label="集团客户编码：" label-width="7em" />
      <van-field readonly required autosize type="textarea" rows="1" name="buildContent" :value="fromdata.buildContent" label="建设内容：" label-width="5em" />
      <van-field readonly required name="supportType" :value="fromdata.supportType" label="支撑类型：" label-width="5em" />
      <van-field readonly required name="emergencyLevel" :value="fromdata.emergencyLevel" label="紧急程度：" label-width="5em" />
      <van-field readonly autosize type="textarea" rows="1" name="datumDescription" :value="fromdata.datumDescription" label="需求描述：" label-width="5em" />
      <van-field readonly required name="applyTime" :value="fromdata.applyTime" label="商机期望响应时间：" label-width="9em" />
      <van-field readonly required name="opportunityAllocationTime" :value="fromdata.opportunityAllocationTime" label="商机分派时间：" label-width="7em" />
      
      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
      <div class="blue_item" />
      <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">承办</span> 
      </div>
      <van-field :readonly="!canChengbanEdit" autosize type="textarea" rows="1" name="undertakeOpinion" v-model="fromdata.undertakeOpinion" label="承办意见：" label-width="5em"
       :right-icon='canChengbanEdit?"arrow":""'/>
      <van-field readonly required name="applyReplyTime" :value="fromdata.applyReplyTime" label="售前支撑响应时间：" label-width="9em" @click="showDateTimePopMethod"
       :right-icon='canChengbanEdit?"arrow":""'/>
         <van-popup v-model='showDateTimePop' round position="bottom" get-container="body">
          <van-datetime-picker title="选择时间"  type="datetime" @cancel="showDateTimePop = false" v-model="currentDate"
            @confirm="DateTimeiPopConfirm" />
        </van-popup>
      <div v-if="todotype==true||toread==true" class="footer">
        <van-button block type="info" native-type="submit" :disabled="canNextInMobile?false:true"
          style="display: inline-block;width:100%;border: 0px solid #60a9ec;">{{ sumitBottonText }}</van-button>
      </div>
    </van-form>
    <historyAndSuggs :showHistory='showHistory' :historydata='historydata' :approveList='approveList' />
  </div>
</template>

<script>
import { getSrqrRequest, getFormDetail, wfWorkItemModel, getWfOptMags } from '@/api/dictapi'
import util from "@/assets/js/public";
import moment from 'moment'
import { mapGetters } from "vuex"
import { Notify, Toast } from "vant";
import historyAndSuggs from "@/views/srqr/historyAndSuggs.vue"
export default {
  data() {
    return {
      active: 0,
      requestError: false,
      params: this.$route.query,
      showHistory: false,
      showDateTimePop: false,//是否显示选择时间对话框
      canNextInMobile: true,//当前环节是否可在手机端办理
      canChengbanEdit:true,//承办模块是否可编辑
      historydata: {},//已办显示当前办理人
      fromdata: {
        handleMethod: '',
        evaluateReason: ''
      },//详情信息
      currentDate: new Date(),
      detailData: {},//详情信息,没啥用，但是服务器递交需要id不得不调用这个接口
      approveList: [],//审批意见列表
       todotype:false,
      toread:false,
    }
  },
  computed: {
    ...mapGetters(['user']),
    ...mapGetters(['userinfo']),
    sumitBottonText: function () {
      if (this.canNextInMobile) {
        return "流转下一步";
      } else {
        return "暂不支持该环节,请至PC端办理";
      }
    },
  },
  components: {
    historyAndSuggs
  },
  //生命周期--创建完成
  created() {
    if(this.params.pmInsType==null&&this.params.processType!=null) {
          this.params.pmInsType = this.params.processType
        }
    if (this.params.todoType % 2 == 0) {
      this.showHistory = true;
    }else if (this.params.todoType % 3 == 0) {
      this.toread = true;
    }else{
      this.todotype = true;
    }
    if (this.params.location == 'dict.start') {
      this.canNextInMobile = false;
    }
    if (this.params.location == 'dict.start'||this.params.location == 'dict.ToStart') {
      this.canChengbanEdit = false;
    }
    if (this.showHistory) {
      this.canChengbanEdit = false;
    }
    this.params.userName = this.user.userName;
    this.getdetail();
  },
  //方法调用
  methods: {
    showDateTimePopMethod: function () {
      if (this.showHistory||!this.canChengbanEdit) return;
      this.showDateTimePop = true;
    },
    DateTimeiPopConfirm(value) {
      this.showDateTimePop = false;
      this.fromdata.applyReplyTime = moment(value).format('YYYY-MM-DD HH:mm:ss');
      console.log("所选日期为",this.fromdata.applyReplyTime);
    },
    //返回
    goBack() {
      this.$router.back(-1) //返回上一页
    },
    //请求出错
    onError(result) {
      this.requestError = true;
      Toast.clear();
      Notify(result.message);
    },
    //获取详情
    getdetail() {
      Toast.loading({
        message: '加载中',
        forbidClick: false
      });
      getFormDetail(this.params).then((result) => {
        if (!result.data) {
          Toast.clear();
          this.onError(result);
          return;
        }
        if (result.data.data) {
          this.detailData = result.data.data;
          this.getFormData();
        }

      })

    },
    getFormData() {
      getSrqrRequest("businessResponse$api$getBusinessResponseByPmInsId", Object.assign(this.params, {
        kv: {
          "source": 'MOBILE',
          "pmInsId": this.params.pmInsId,
          "currentUserCode": util.encrypt(this.params.userName),
        }
      })
      ).then((result) => {
        Toast.clear();
        if (!result.data) {
          this.onError(result);
          return;
        }
        if (result.data.data) {
          this.fromdata = result.data.data;
          if (this.fromdata.applyReplyTime==null||this.fromdata.applyReplyTime==""){
            this.fromdata.applyReplyTime=moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
          }
          if (this.showHistory) {
            this.wfWorkItemModel();
          }
          this.getWfOptMags();
        }

      })
    },
    //获取已办下一处理人
    wfWorkItemModel() {
      wfWorkItemModel(this.params)
        .then((result) => {
          if (!result.data) {
            Notify(result.message);
            return;
          }
          if (result.data.data) {
            this.historydata = result.data.data
            this.historydata.MANAGER = this.historydata.participantName || '暂无';
            this.historydata.DEPARTMENT = this.historydata.workItemName || '暂无';
          }
        })
    },
    //获取审批意见
    getWfOptMags() {
      getWfOptMags(this.params)
        .then((result) => {
          if (!result.data) {
            Notify(result.message);
            return;
          }
          this.approveList = result.data.data.reverse();
        })
    },
    //下一步流转
    submitFromData() { //提交流转
      var formSendData = { "htmlParamMap": {} };
      formSendData.htmlParamMap = this.fromdata;
      formSendData.id = this.detailData.id;
      formSendData.pmInsId = this.params.pmInsId;
      formSendData.processType = this.params.pmInsType
      formSendData.workItemId = this.params.workItemId;

      var params1 = {
        kv: {
          currentUserCode: util.encrypt(this.params.userName),
          source: 'MOBILE',
          location: this.params.location,
          processInstId: this.params.processInstId,
          processDefName: this.params.processDefName,
          processType: this.params.pmInsType,
        },
      };
      var params2 = {
        kv: {
          "currentUserCode": util.encrypt(this.params.userName),
          "source": 'MOBILE',
          "location": this.params.location,
          "processInstId": this.params.processInstId,
          'processType': this.params.pmInsType,
          'receiptCode': this.params.processInstId
        },
      };
      var params3 = {
        kv: {
          "source": 'MOBILE',
          "currentUserCode": util.encrypt(this.params.userName),
          "workItemId": this.params.todoType==3?"":this.params.workItemId,
          "processInstId": this.params.processInstId,
          "location": this.params.location,
          "notificationId":this.params.todoType==3?this.params.wfnid:""
        },
      };
      localStorage.setItem('submitPageParam', JSON.stringify({
        getDecisionsUrl: 'decisionAndUser$api$getDecisions',
            getDecisionsParams: params1,
            getUserUrl: 'decisionAndUser$api$getOrgAndUser',
            getUserParams: params2,
            tosubmintUrl: 'applicationFormEnhance$api$startSubmitProcess',
            tosubmintParams: params3,
            formData: formSendData,
            fromMoa:this.params.fromMoa,
            type:this.params.todoType==3?"toRead":"toDo"
          }));
      this.$router.push(
        {
          name: 'srqrsubmit'
        }
      );
    },

  }
}
</script>
<style  scoped>
.errorPlace {
  position: absolute;
  margin-top: -80px;
  top: 50%;
  margin-left: -50px;
  left: 50%;
}

.file-list {
  border: 1px solid #60a9ec;
  margin: 5px 10px 5px 10px;
  padding: 5px 0px 5px 0px;
  border-radius: 10px;
}

.label-lesson {
  padding-left: 15px;
  color: #ea0023;
  font-size: 12px;
}
</style>
